<template xmlns:v-on="http://www.w3.org/1999/xhtml" xmlns:v-bind="http://www.w3.org/1999/xhtml">
  <div id="app" class="hello">
    <h1>{{ msg }}</h1>
    <input type="text" v-model="user.name"/>
    <input type="password" v-model='user.password'/>
    <!-- method handler -->
    <button v-on:click="dologin">登录</button>

  </div>
</template>

<script>
import {mapActions,mapState} from 'vuex'

export default {
  name: 'hello',
  data () {
    return {
      msg: 'Welcome to Your Vue.js App',
    }
  },
  computed: mapState(['user','userInfo']),
  methods:{
    dologin:function(){
      // POST /someUrl
      this.login({loginName: this.user.name, password: this.user.password}).then((data) => {
      console.log(data)
         if(data.code === 200){
            this.$router.push({path: '/home'})
         }else{
            console.log(data.message)
         }
      }).catch(msg => console.log(msg));
    },
     ...mapActions(['login'])
  }
}




</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
h1, h2 {
  font-weight: normal;
}

ul {
  list-style-type: none;
  padding: 0;
}

li {
  display: inline-block;
  margin: 0 10px;
}

a {
  color: #42b983;
}




</style>
